All files / web/src/app/api/arcade/rooms/[roomId]/reports route.ts

0% Statements 0/36
0% Branches 0/1
0% Functions 0/1
0% Lines 0/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
import { NextResponse } from 'next/server'
import { getAllReports } from '@/lib/arcade/room-moderation'
import { getRoomMembers } from '@/lib/arcade/room-membership'
import { withAuth } from '@/lib/auth/withAuth'
import { getUserId } from '@/lib/viewer'

/**
 * GET /api/arcade/rooms/:roomId/reports
 * Get all reports for a room (host only)
 */
export const GET = withAuth(async (_request, { params }) => {
  try {
    const { roomId } = (await params) as { roomId: string }
    const userId = await getUserId()

    // Check if user is the host
    const members = await getRoomMembers(roomId)
    const currentMember = members.find((m) => m.userId === userId)

    if (!currentMember) {
      return NextResponse.json({ error: 'You are not in this room' }, { status: 403 })
    }

    if (!currentMember.isCreator) {
      return NextResponse.json({ error: 'Only the host can view reports' }, { status: 403 })
    }

    // Get all reports
    const reports = await getAllReports(roomId)

    return NextResponse.json({ reports }, { status: 200 })
  } catch (error: any) {
    console.error('Failed to get reports:', error)
    return NextResponse.json({ error: 'Failed to get reports' }, { status: 500 })
  }
})